<?php

namespace Tests\Browser\Pages\Wechat\Contracts;

use App\Models\OpenWechat\Authorizer;
use App\Models\OpenWechat\WechatUser;
use Tests\Browser\Pages\Page;

abstract class WechatAbstractPage extends Page
{
    protected $wechatUser;
    protected $authorizer;

    public function __construct(WechatUser $wechatUser,
                                Authorizer $authorizer)
    {
        $this->wechatUser = $wechatUser;
        $this->authorizer = $authorizer;
    }

    /**
     * Get the URL for the page.
     *
     * @return string
     */
    public function url()
    {
        return $this->spaRouteUrl();
    }

    protected function spaRouteUrl(string $path = "/"): string
    {
        return "/wx-system/?openid={$this->wechatUser->openid}&appid={$this->authorizer->authorizer_appid}#{$path}";
    }

    /**
     * Get the element shortcuts for the page.
     *
     * @return array
     */
    public function elements()
    {
        return [
            '@user-info-btn' => '.info',
        ];
    }
}
